package com.woniu.config;

import com.woniu.utils.ConstantUtil;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class SurgeryRabbitConfig {
    @Bean
    public CustomExchange surgeryReminderExchange() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        return new CustomExchange(
                ConstantUtil.EXCHANGE_SURGERY_REMINDER,
                "x-delayed-message",
                true,
                false,
                map);
    }

    @Bean
    public Queue surgeryReminderQueue() {
        return new Queue(ConstantUtil.QUEUE_SURGERY_REMINDER, true);
    }

    @Bean
    public Binding surgeryReminderBinding() {
        return BindingBuilder.bind(surgeryReminderQueue())
                .to(surgeryReminderExchange())
                .with(ConstantUtil.ROUTING_KEY_SURGERY_REMINDER)
                .noargs();
    }
}
